package locations.dao.implement;


import java.util.List;
import locations.dao.InstitutionTypeDAO;
import locations.model.InstitutionType;

public class InstitutionTypeDAOHibernateJPA extends GenericDAOHibernateJPA<InstitutionType>
implements
InstitutionTypeDAO {
	
    public InstitutionTypeDAOHibernateJPA() {
            super(InstitutionType.class);
    }

    @Override
    public boolean exists(String name, long id)
    {
        boolean started = this.getTransaction().isActive();
        if (!started)
        {
            this.getTransaction().begin();            
        }
        String queryId = (id == 0 ? "" :  " and i.id !='" + id + "'");
        List result= entityManager.createQuery
                ("from InstitutionType i where i.name='" + name + "'" + queryId).getResultList();
//            this.getTransaction().commit();            
        return ! result.isEmpty();
    }

}
